package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.dto.product.ProductDto;
import com.atguigu.spzx.model.dto.product.ProductSaveDto;
import com.atguigu.spzx.model.vo.product.ProductVo;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "商品管理模块")
@RequestMapping("/admin/product/product")
public class ProductController {
    @Resource
    ProductService productService;

    ///updateAuditStatus/9/-1
    @Operation(summary = "商品审批接口")
    @GetMapping("updateAuditStatus/{id}/{auditStatus}")
    public Result updateAuditStatus(@PathVariable("id")Long id,
                                    @PathVariable("auditStatus")Integer auditStatus){
        productService.updateAuditStatus(id , auditStatus);
        return Result.ok();
    }
    @Operation(summary = "商品上下架接口")
    @GetMapping("updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable("id")Long id,
                                    @PathVariable("status")Integer status){
        productService.updateStatus(id , status);
        return Result.ok();
    }
    @Operation(summary = "删除商品接口")
    @DeleteMapping("deleteById/{id}")
    public Result deleteById(@PathVariable("id")Long id){
        productService.deleteById(id);
        return Result.ok();
    }
    @Operation(summary = "更新商品接口")
    @PutMapping("/updateById")
    public Result updateById(@RequestBody ProductSaveDto productSaveDto){
        productService.updateById(productSaveDto);
        return Result.ok();
    }
    @Operation(summary = "根据id查询商品接口")
    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable("id")Long id){
        ProductSaveDto productSaveDto = productService.getById(id);
        return Result.ok().data(productSaveDto);
    }
    @Operation(summary = "新增商品接口")
    @PostMapping("save")
    public Result save(@RequestBody ProductSaveDto productSaveDto){
        productService.save(productSaveDto);
        return Result.ok();
    }
    @Operation(summary = "查询商品分页列表接口")
    @GetMapping("{pageNum}/{pageSize}")
    public Result page(@PathVariable("pageNum")Integer pageNum,
                       @PathVariable("pageSize")Integer pageSize,
                       ProductDto productDto){
        PageInfo<ProductVo> pageInfo = productService.page(pageNum,pageSize,productDto);
        return Result.ok().data(pageInfo);
    }


}
